<!DOCTYPE html>
<html class="x-admin-sm">

	<head>
		<meta charset="UTF-8">
		<title>欢迎页面-X-admin2.2</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
		<link rel="stylesheet" href="../../css/font.css">
		<link rel="stylesheet" href="../../css/xadmin.css">
		<script src="../../js/base.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../lib/layui/layui.js" charset="utf-8"></script>
		<script type="text/javascript" src="../../js/xadmin.js"></script>
		<!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
		<style type="text/css">
			.table-select {
				display: none;
				position: fixed !important;
				left: inherit !important;
				top: inherit !important;
				padding: 5px 0;
				z-index: 899;
				/* min-width: 100%; */
				border: 1px solid #d2d2d2;
				max-height: 300px;
				overflow-y: auto;
				background-color: #fff;
				border-radius: 2px;
				box-shadow: 0 2px 4px rgba(0, 0, 0, .12);
				box-sizing: border-box
			}
		</style>

	</head>

	<body>
		<div class="x-nav">
			<span class="layui-breadcrumb">
				<a href="">首页</a>
				<a href="">基础设置</a>
				<a>
					<cite>科室指标集选择</cite></a>
			</span>
			<a class="layui-btn layui-btn-small select" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()"
			 title="刷新">
				<i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
			</a>
		</div>
		<script type="text/html" id="barDemo">

		</script>
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">

						<div class="layui-card-body ">
							<!-- <div class="layui-inline">
								<label>指标类别:</label>
								<div class="layui-input-inline">
									<input type="text" id="account_date" name="account_date" autocomplete="off" class="layui-input">
								</div>
							</div>
							<div class="layui-inline">
								<button class="layui-btn select layui-btn-sm" onclick="select()"  id="btn_select" style="display:none"> <i class="layui-icon"></i>查询 </button>
							</div> -->
							<table class="layui-table" lay-filter="table" id="table">

							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
	</body>
	<script type="text/html" id="toolbarDemo">
		<div class = "layui-btn-container" > 
            
        </div > 
    </script>

	<script type="text/html" id="select_guide_gathers_name">
		<select lay-filter="select_guide_gather_code">
			<option value="" >未选择</option>
			{{#  layui.each(d.list, function(index, item){ }}
				{{# if (item.guide_gather_code == d.gather_code) { }}
					<option value="{{d.dept_code}}-{{d.account_date}}-{{item.guide_gather_code}}" selected>{{item.guide_gather_name}}</option>
				{{# } else { }}
					<option value="{{d.dept_code}}-{{d.account_date}}-{{item.guide_gather_code}}">{{item.guide_gather_name}}</option>
				{{# } }}
			{{#  }); }}
		</select>
	</script>

	<script type="text/html" id="guide_unit_tpl">
		<!-- 这里的 checked 的状态只是演示 -->
      <input type="checkbox" name="sex" value="{{d.guide_code}}" lay-skin="switch" lay-text="是|否" lay-filter="guide_unit" {{ d.guide_unit == 'T' ? 'checked' : '' }}>
    </script>

	<script>
		layui.use("laydate",
			function() {
				var laydate = layui.laydate;

				//执行一个laydate实例
				laydate.render({
					elem: "#account_date", //指定元素
					type: "month"
				});

				//执行一个laydate实例
				laydate.render({
					elem: "#end" //指定元素
				});

			});
	</script>
	<script>
		var account_date = get('account_date');
		var dept_code = get('dept_code');
		var table = null;
		var form = null;
		layui.use(["table", "form"],
			function() {
				table = layui.table;
				form = layui.form;
				select();
				//监听单元格编辑
				table.on("tool(table)", function(obj) {

					var data = obj.data;
					//console.log(obj)
					if (obj.event === "del") {
						layer.confirm("真的删除行么", function(index) {
							// console.log(data.uuid);

							var uuid = data.uuid
							$.post(root + "index/table_delete", {
									uuid: uuid,
									table: "guide_gather_class"
								},
								function(data) {
									if (data.code == 0) {
										obj.del();
										layer.alert(data.msg, {
											icon: 6
										});
									} else {
										layer.alert(data.msg, {
											icon: 2
										});
									}
								}
							);

							layer.close(index);
						});
					}
					if (obj.event == "show") {
						xadmin.open("指标选择", "save_zhibiaoji.html?guide_gather_code=" + data.guide_gather_code, 800, 600)
					}
					if (obj.event === "edit") {

						var data = obj.data;
						console.log(data);
						xadmin.open("编辑", "edit_keshi.html", 800, 600)

					}

				});
				table.on("tool(test)",
					function(obj) {




					});

				form.on('switch(guide_unit)', function(obj) {
					var value = obj.value;
					//field = field.toUpperCase();
					var checked = obj.elem.checked;
					if(checked)
					{
						checked = "T";
					}
					else
					{
						checked = "F";
					}
					var table = "hospitalsys.dept_guide_information";
					var pk = {
						"dept_code": dept_code,
						"station_year": account_date,
						guide_code: value
					};
					var col = "guide_unit";
					$.post(root + "Kpizhibiaoshezhi/set_field", {
							value: checked,
							col: col,
							table: table,
							pk: pk
						},
						function(data) {



						});

				
			});

		//头工具栏事件
		table.on("toolbar(table)",
			function(obj) {
				var checkStatus = table.checkStatus(obj.config.id);
				switch (obj.event) {
					case "add":
						xadmin.open("添加", "add.html", 800, 600)
						break;
					case "select_keshi":
						xadmin.open("科室选择", "select_keshi.html", 800, 600)
						break;
					case "getCheckLength":
						var data = checkStatus.data;
						layer.msg("选中了：" + data.length + " 个");
						break;
					case "isAll":
						layer.msg(checkStatus.isAll ? "全选" : "未全选");
						break;
				};
			});

		table.on('edit(table)', function(obj) {
			var value = obj.value //得到修改后的值
				,
				data = obj.data //得到所在行所有键值
				,
				field = obj.field; //得到字段
			//field = field.toUpperCase();
			var table = "hospitalsys.dept_guide_information";
			var pk = {
				"dept_code": data.dept_code,
				"station_year": account_date,
				guide_code: data.guide_code
			};
			var col = field;
			
			
			
			$.post(root + "Kpizhibiaoshezhi/set_field", {
					value: value,
					col: col,
					table: table,
					pk: pk
				},
				function(data) {



				});

		});

		form.on('select(select_guide_gather_code)', function(obj) {
		if (obj.value == "") {
			return false;
		}
		var arr = obj.value.split("-");

		var value = arr[2];
		var col = "gather_code";
		var table = "hospitalsys.dept_guide_information";
		var pk = {
			"dept_code": arr[0],
			"station_year": arr[1]
		};

		$.post(root + "Kpizhibiaoshezhi/set_field", {
				value: value,
				col: col,
				table: table,
				pk: pk
			},
			function(data) {



			});


		});
		});

		function select() {

			table.render({
				elem: "#table",
				id: "table",
				toolbar: "#toolbarDemo",
				url: root + "Kpizhibiaoshezhi/edit_keshi",
				page: true,
				cellMinWidth: 100,
				cols: [
					[ //表头
						{
							align:"center",field: "guide_name",
							title: "指标名称"
						}, {
							align:"center",field: "increase",
							title: "增加量",
							edit: "text"
						}, {
							align:"center",field: "increase_arithmetic",
							title: "增加得分",
							edit: "text"
						}, {
							align:"center",field: "decrease",
							title: "降低量",
							edit: "text"
						}, {
							align:"center",field: "decrease_arithmetic",
							title: "降低得分",
							edit: "text"
						}, {
							align:"center",field: "guide_unit",
							title: "是否百分数",
							templet: '#guide_unit_tpl'
						}, {
							align:"center",field: "guide_cause",
							title: "目标值",
							edit: "text"
						}, {
							align:"center",field: "guide_value",
							title: "权重",
							edit: "text"
						}, {
							align:"center",field: "plus_limit",
							title: "加分限制",
							edit: "text"
						}, {
							align:"center",field: "minus_limit",
							title: "减分限制",
							edit: "text"
						}
					]
				],
				where: {
					account_date: account_date,
					dept_code: dept_code
				},
				done: function(res, curr, count) {

				}
			});
			//form.render('select');
		}
	</script>
	<script>
		var _hmt = _hmt || [];
		(function() {
			var hm = document.createElement("script");
			hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
			var s = document.getElementsByTagName("script")[0];
			s.parentNode.insertBefore(hm, s);
		})();
	</script>

</html>
